/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.permission.controller;

import java.util.List;
import queenb.net.entitybean.B050;
import queenb.web.controller.QueenbController;
import queenb.web.permission.store.B050Store;
import queenb.web.util.ContextUtil;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class B050Controller extends QueenbController {
    // private ComboboxUtil comboboxUtil;

    private int PB050;
    private String BV051;
    private String BV052;
    private B050Store b050Store;
    private String pagereload;

    public B050Controller() {
        b050Store = new B050Store();
        Object pb050Object = getRequest().getParameter("pb050");
        try {
            if (pb050Object != null) {
                this.PB050 = Util.parseInt(pb050Object);
                getListS250DetailEdit(PB050);
            }
            this.pagereload = getRequest().getParameter("page");
            if (this.pagereload == null) {
                this.pagereload = ContextUtil.getRequestParameter("page");
            }
            System.out.println("pagereload 1----" + pagereload);
        } catch (Exception ex) {
        }
    }

    public void getListS250DetailEdit(int pv200i) {
        this.PB050 = pv200i;
        try {
            List<B050> listB050ByID = getListB050All();
            if (listB050ByID.size() > 0) {
                for (int i = 0; i < listB050ByID.size(); i++) {
                    if (listB050ByID.get(i).getPB050() == PB050) {
                        this.BV051 = listB050ByID.get(i).getBV051();
                        this.BV052 = listB050ByID.get(i).getBV052();

                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("ERROR : " + ex.getMessage());
        }

    }

    public List<B050> getListB050All() {
        try {
            List<B050> listB050 = b050Store.getListB050All(getLogin().getModule(), getLogin().getCompanyNo(), null, getLogin().getUserName());
            return listB050;
        } catch (Exception e) {
            return null;

        }
    }

    public void update() {
        System.out.println("update 2----" + PB050+"--BV051-"+BV051+"---BV052-"+BV052);
        int count = b050Store.update(PB050, getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, 0, BV051, BV052, null, null, 0, 0, 0, 0, 0, null, 0, 0, getLogin().getUserName());
        if (count > 0) {
            showGlobalReport(true, getResourceString("datasavesuccessful"));
        } else {
            showGlobalReport(true, getResourceString("datasuccessfail"));
        }
        System.out.println("pagereload 2----" + pagereload);
        if (pagereload.equals("project.jsp")) {
            sendRedirectUrlTab("project.jsp?fis=0&linkproject="+Util.convertMD5(getRequest().getRequestURI()));
        } else {
            sendRedirectUrlTab("setting.jsp?tab=header9&link9="+Util.convertMD5(getRequest().getRequestURI()));
        }
    }

//    public List<SelectItem> getListItemS200Work()
//    {
//        comboboxUtil = new ComboboxUtil();
//        return comboboxUtil.getListComBS200Work();
//    }
    /**
     * @return the PB050
     */
    public int getPB050() {
        return PB050;
    }

    /**
     * @param PB050 the PB050 to set
     */
    public void setPB050(int PB050) {
        this.PB050 = PB050;
    }

    /**
     * @return the BV051
     */
    public String getBV051() {
        return BV051;
    }

    /**
     * @param BV051 the BV051 to set
     */
    public void setBV051(String BV051) {
        this.BV051 = BV051;
    }

    /**
     * @return the BV052
     */
    public String getBV052() {
        return BV052;
    }

    /**
     * @param BV052 the BV052 to set
     */
    public void setBV052(String BV052) {
        this.BV052 = BV052;
    }

    /**
     * @return the pagereload
     */
    public String getPagereload() {
        return pagereload;
    }

    /**
     * @param pagereload the pagereload to set
     */
    public void setPagereload(String pagereload) {
        this.pagereload = pagereload;
    }
}
